#!/bin/bash -e

function info() {
echo Usage: `basename $0` '[-l in.bed -m(somatic) -g(single_cell)] snp.vcf indel.vcf'
exit 65
}

while getopts ":p:l:mgh" opts
do
case $opts in
	m) somatic=T;;
	g) single_cell=T;;
	l) interval=$OPTARG;;
	p) out_prefix=$OPTARG;;
	\?) info;;
esac
done
shift $(($OPTIND - 1))

test $# -lt 1 && info


. /mnt/ilustre/app/medical/tools/.var

# common anno first

anno_common.sh -p$out_prefix.indel -l $interval $2 &
anno_common.sh -p$out_prefix.snp -l $interval $1

wait

# anno vep

# anno snpeff and snpsift

# anno star

# anno annovar

annovar.sh -p$out_prefix.indel $out_prefix.indel.anno.common.vcf &
annovar.sh -p$out_prefix.snp $out_prefix.snp.anno.common.vcf 
wait 


# spesific anno second

# anno filter
# common filter

filter_gatk.sh -p$out_prefix -i -l $interval $out_prefix.indel.anno.common.vcf &
filter_gatk.sh -p$out_prefix -l $interval $out_prefix.snp.anno.common.vcf



wait



# spesific filter

# nprot anno filter
if test -n "$single_cell"; then
nprot_anno.sh -p$out_prefix $out_prefix.snp.filtered.vcf $out_prefix.indel.filtered.vcf




#---------------------------
# segment high low
	if test -n "$somatic"; then
		filters.sh -g -m -p$out_prefix $out_prefix.snp.nprot.vcf $out_prefix.indel.nprot.vcf
	else
		filters.sh -g -p$out_prefix $out_prefix.snp.nprot.vcf $out_prefix.indel.nprot.vcf
	fi

else 
	if test -n "$somatic"; then
		filters.sh -m -p$out_prefix $out_prefix.snp.filtered.vcf $out_prefix.indel.filtered.vcf
	else
		filters.sh -p$out_prefix $out_prefix.snp.filtered.vcf $out_prefix.indel.filtered.vcf
	fi
fi
# high low anno

impact.sh -p$out_prefix $out_prefix.high.vcf $out_prefix.low.vcf

. $cmd_done

